package cn.sciento.core.endpoint;

import java.util.Map;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.util.CollectionUtils;

public interface HttpRequest<T> {
  String getSchema();
  
  String getUrl();
  
  HttpMethod getMethod();
  
  HttpEntity<byte[]> getHttpEntity();
  
  Class<T> getResponseClass();
  
  default String toString(Map<String, String> requestParams) {
    if (CollectionUtils.isEmpty(requestParams)) {
      return "";
    }
    StringBuilder builder = new StringBuilder("?");
    for (Map.Entry<String, String> entry : requestParams.entrySet()) {
      builder.append("&")
        .append(entry.getKey())
        .append("=")
        .append(entry.getValue());
    }
    return builder.deleteCharAt(1).toString();
  }
}
